﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 特效
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void grid_MouseMove(object sender, MouseEventArgs e)
        {
            double width = grid.ActualWidth;
            double height = grid.ActualHeight;
            Point centerPoint = new Point(width / 2, height / 2);
            Point mousePoint = e.GetPosition(grid);

            //与X轴的夹角
            double angle = Math.Atan2(
                mousePoint.Y - centerPoint.Y,
                mousePoint.X - centerPoint.X); //弧度
            double theta = angle * 180 / Math.PI;// 角度
            this.Title = $"角度={theta}";

            DropShadowEffect dropShadowEffect = button.Effect as DropShadowEffect;

            //计算距离
            var distance = Math.Sqrt(
                (Math.Pow(mousePoint.X - centerPoint.X, 2)
                + Math.Pow(mousePoint.Y - centerPoint.Y, 2)));

            dropShadowEffect.Direction = -theta;//设置阴影角度
            dropShadowEffect.ShadowDepth = distance / 10;//设置阴影偏移量
            dropShadowEffect.BlurRadius = distance / 10 * 2;//设置模糊程度
        }

        private void grid_MouseMove2(object sender, MouseEventArgs e)
        {
            double width = grid.ActualWidth;
            double height = grid.ActualHeight;
            Point centerPoint = new Point(width / 2, height / 2);
            Point mousePoint = e.GetPosition(grid);

            BlurEffect effect = ellipse.Effect as BlurEffect;

            //计算距离
            var distance = Math.Sqrt(
                (Math.Pow(mousePoint.X - centerPoint.X, 2)
                + Math.Pow(mousePoint.Y - centerPoint.Y, 2)));

            effect.Radius = distance / 5;//设置模糊

            this.Title = $"距离={distance}";
        }
    }
}